<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仿淘宝滑块验证码</title>
    <!-- 引入css文件和js文件 -->
    <script type="text/javascript" charset="utf-8" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="./js/drag.js"></script>
    <style>
        .container{
            width: 500px;
            margin: 0 auto;
        }

        button{
            margin-top: 10px;
        }
        #drag{ 
            position: relative;
            background-color: #e8e8e8;
            width: 300px;
            height: 34px;
            line-height: 34px;
            text-align: center;
        }
        #drag .handler{
            position: absolute;
            top: 0px;
            left: 0px;
            width: 40px;
            height: 32px;
            border: 1px solid #ccc;
            cursor: move;
        }
        .handler_bg{
            background: #fff url("") no-repeat center;
        }
        .handler_ok_bg{
            background: #fff url("") no-repeat center;
        }
        #drag .drag_bg{
            background-color: #7ac23c;
            height: 34px;
            width: 0px;
        }
        #drag .drag_text{
            position: absolute;
            top: 0px;
            width: 300px;
            -moz-user-select: none;
            -webkit-user-select: none;
            user-select: none;
            -o-user-select:none;
            -ms-user-select:none; 
        }
    </style>
</head>
<body>
    <div class="container">
        <div id="drag"></div>
        <button onclick="isDrag()">确定</button>
    </div>
    <script type="text/javascript">
        $('#drag').drag({'width':'200px'});
        function isDrag(){
            var isdrag = $('#drag .drag_bg').outerWidth(true);
            if(isdrag == 0){
                alert("请滑动滑块进行验证");
                return;
            } else{
                alert("验证通过");
            }
        }
    </script>
</body>
</html>